<%-- 
    Document   : mantenimientos
    Created on : 08/10/2013, 05:33:25 AM
    Author     : grakeskull
--%>

<%@page import="edu.capex.farmacus.encapsulates.Supervisores"%>
<%@page import="edu.capex.farmacus.Manager.SupervisoresManager"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>

<%
    Supervisores supervisorAMod = null;

    if (request.getParameter("nombre") != null && request.getParameter("cedula") != null
            && request.getParameter("telefono") != null && request.getParameter("correo") != null
            && request.getParameter("id") != null && request.getParameter("moid") == null) {

        //Supervisores supervisor = new Supervisores(new Integer(request.getParameter("id")));
        Supervisores supervisor = new SupervisoresManager().findSupervisores(new Integer(request.getParameter("id")));
        boolean existe = false;

        if (supervisor == null) {
            supervisor = new Supervisores();
        } else {
            existe = true;
        }


        supervisor.setCedulaSupervisores(request.getParameter("cedula"));
        supervisor.setCorreoSup(request.getParameter("correo"));
        supervisor.setTelefonoSupervisor(request.getParameter("telefono"));
        supervisor.setNombresupervisores(request.getParameter("nombre"));

        if (existe) {
            new SupervisoresManager().edit(supervisor);
        } else {
            new SupervisoresManager().create(supervisor);
        }

    } else if (request.getParameter("moid") != null && request.getParameter("modificar").equalsIgnoreCase("modificar")) {
        supervisorAMod = new SupervisoresManager().findSupervisores(new Integer(request.getParameter("moid")));
    } else if (request.getParameter("reid") != null && request.getParameter("eliminar").equalsIgnoreCase("eliminar")) {
        new SupervisoresManager().destroy(new Integer(request.getParameter("reid")));
    }

%>

<html>
    <head>
        <%@include file="/resources/header.jsp" %>
        <script src="../js/bsa.js"></script>
    </head>
    <%@include file="/resources/header1.jsp" %>
    <body class="preview" data-spy="scroll" data-target=".subnav" data-offset="80">

        <div class="container">
            
            <%@include file="/admin/supervisores/menuadm.jsp" %>

            <h2>Mantenimiento Supervisor </h2>
            
            <section id="forms">
                
                <form class="form-horizontal well" method="POST" id="myForm">
                    <fieldset>

                        <%if (supervisorAMod != null) {%>

                        <input type="hidden" name="id" value="<%=supervisorAMod.getIdsupervisores()%>"/>
                        <div class="control-group">
                            <label class="control-label" for="input01">Nombre</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="nombre" value="<%=supervisorAMod.getNombresupervisores()%>"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="input01">Cedula</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="cedula" value="<%=supervisorAMod.getCedulaSupervisores()%>"/>
                            </div>  
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="input01">Telefono</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="telefono" value="<%=supervisorAMod.getTelefonoSupervisor()%>"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="input01">Correo</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="correo" value="<%=supervisorAMod.getCorreoSup()%>"/>
                            </div>
                        </div>



                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary" name="modificar">Modificar</button>
                            <button type="reset" class="btn">Cancelar</button>
                        </div>
                        <%} else {%>
                        <input type="hidden" name="id" value="<%=new SupervisoresManager().nextId()%>"/>
                        <div class="control-group">
                            <label class="control-label" for="input01">Nombre</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="nombre">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="input01">Cedula</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="cedula">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="input01">Telefono</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="telefono">
                            </div>
                        </div>

                        <div class="control-group">
                            <label class="control-label" for="input01">Correo</label>
                            <div class="controls">
                                <input type="text" class="input-xlarge" data-required id="input01" name="correo">
                            </div>
                        </div>



                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary" name="guardar">Agregar</button>
                            <button type="reset" class="btn">Cancelar</button>
                        </div>
                        <%}%>
                    </fieldset>
                </form>

                <table id="myTable" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>
                                Nombre
                            </th>
                            <th>
                                Cedula
                            </th>
                            <th>
                                Telefono
                            </th>
                            <th>
                                Correo
                            </th>
                            <th filter="false">
                                Modificar
                            </th>
                            <th filter="false">
                                Eliminar
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <%
                            for (Supervisores temp : new SupervisoresManager().findSupervisoresEntities()) {
                        %>
                        <tr>
                            <td>
                                <%=temp.getNombresupervisores()%>
                            </td>
                            <td>
                                <%=temp.getCedulaSupervisores()%>
                            </td>
                            <td>
                                <%=temp.getTelefonoSupervisor()%>
                            </td>
                            <td>
                                <%=temp.getCorreoSup()%>
                            </td>
                            <td>
                                <form action="#" method="POST">
                                    <center>
                                        <input type="hidden" name="moid" value="<%=temp.getIdsupervisores()%>"/>
                                        <input type="submit" name="modificar" value="Modificar" class="btn"/>
                                    </center>
                                </form>
                            </td>
                            <td>
                                <form action="#" method="POST">
                                    <center>
                                        <input type="hidden" name="reid" value="<%=temp.getIdsupervisores()%>"/>
                                        <input type="submit" name="eliminar" value="Eliminar" class="btn"/>
                                    </center>
                                </form>
                            </td>
                        </tr>
                        <%}%>
                    </tbody>
                </table>

                <%@include file="/resources/footer1.jsp" %>
            </section>
        </div>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#myTable").tableFilter();
                $('#myForm').validate({
                    onKeyup: true,
                    eachValidField: function() {

                        $(this).closest('div').removeClass('error').addClass('success');
                    },
                    eachInvalidField: function() {

                        $(this).closest('div').removeClass('success').addClass('error');
                    }
                });

            });
        </script>
    </body>
</html>
